//
//  LHJokeImageCell.m
//  Project_B
//
//  Created by dllo on 15/12/23.
//  Copyright © 2015年 ZY. All rights reserved.
//

#import "LHJokeImageCell.h"

@implementation LHJokeImageCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return self;
}
- (void)createSubView {
    
    self.picImage = [UIImageView new];
    [self.contentView addSubview:self.picImage];
    
    //    摘要
    self.digestLable = [UILabel new];
    self.digestLable.numberOfLines = 0;
    self.digestLable.font = [UIFont systemFontOfSize:14.0];
    [self.contentView addSubview:self.digestLable];
    [self.digestLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(10);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH-20, 200));
    }];
    
    //收藏button
    self.button = [UIButton new];
    [self.button setBackgroundImage:[UIImage imageNamed:@"audionews_share_button@2x.png"] forState:(UIControlStateNormal)];
    [self.contentView addSubview:self.button];
    [self.button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.bottom.equalTo(@-10);
        make.size.mas_equalTo(CGSizeMake(30, 30));
    }];
    //设置圆角
    self.button.layer.masksToBounds = YES;
    self.button.layer.cornerRadius = 15;
    self.button.layer.borderWidth = 1;
    self.button.layer.borderColor = [UIColor colorWithWhite:0.877 alpha:1.000].CGColor;
    
    //不赞
    self.notzanBgImageView = [UIImageView new];
    self.notzanBgImageView.image = [UIImage imageNamed:@"duanzi_button_normal@2x.png"];
    [self.contentView addSubview:self.notzanBgImageView];
    [self.notzanBgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.button);
        make.right.equalTo(self.button.mas_left).offset(-8);
        make.size.mas_equalTo(CGSizeMake(50, 30));
    }];
    
    self.notZanLableNum = [UILabel new];
    self.notZanLableNum.font = [UIFont systemFontOfSize:12];
    self.notZanLableNum.textColor = [UIColor grayColor];
    self.notZanLableNum.textAlignment = NSTextAlignmentLeft;
    [self.notzanBgImageView addSubview:self.notZanLableNum];
    [self.notZanLableNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.top.equalTo(@0);
        make.size.mas_equalTo(CGSizeMake(20, 30));
    }];
    
    self.notzanimageView = [UIImageView new];
    self.notzanimageView.image = [UIImage imageNamed:@"duanzi_down@2x.png"];
    [self.notzanBgImageView addSubview:self.notzanimageView];
    [self.notzanimageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@8);
        make.right.offset(-8);
        make.size.mas_equalTo(CGSizeMake(15, 15));
    }];
    
    
    //赞
    self.zanBgImage = [UIImageView new];
    self.zanBgImage.image = [UIImage imageNamed:@"duanzi_button_normal@2x.png"];
    [self.contentView addSubview:self.zanBgImage];
    [self.zanBgImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.button);
        make.right.equalTo(self.notzanBgImageView.mas_left).offset(-8);
        make.size.mas_equalTo(CGSizeMake(50, 30));
    }];
    
    
    
    self.zanLableNum = [UILabel new];
    self.zanLableNum.textColor = [UIColor grayColor];
    self.zanLableNum.font = [UIFont systemFontOfSize:12];
    [self.zanBgImage addSubview:self.zanLableNum];
    [self.zanLableNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.top.equalTo(@0);
        make.size.mas_equalTo(CGSizeMake(20, 30));
    }];
    
    self.zanimageView = [UIImageView new];
    self.zanimageView.image = [UIImage imageNamed:@"duanzi_up@2x.png"];
    [self.zanBgImage addSubview:self.zanimageView];
    [self.zanimageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@8);
        make.right.offset(-8);
        make.size.mas_equalTo(CGSizeMake(15, 15));
    }];
    
    UIView *aview = [UIView new];
    aview.backgroundColor = [UIColor grayColor];
    [self.contentView addSubview:aview];
    [aview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 3));
        
    }];
}

- (void)setJokeModel:(JokeModel *)jokeModel
{
    //内容
    _digestLable.text = jokeModel.digest;
    [self.digestLable mas_updateConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.mas_equalTo(10);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH-20, jokeModel.h));
    }];
    
    //不赞
    [self.notzanBgImageView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.button);
        make.right.equalTo(self.button.mas_left).offset(-8);
        make.size.mas_equalTo(CGSizeMake(30+jokeModel.downW+10, 30));
    }];
    
    _notZanLableNum.text = [NSString stringWithFormat:@"%ld", (long)jokeModel.downTimes];
    [self.notZanLableNum mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.top.equalTo(@0);
        make.size.mas_equalTo(CGSizeMake(jokeModel.downW+10, 30));
    }];
    
    //赞
    [self.zanBgImage mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.notzanBgImageView);
        make.right.equalTo(self.notzanBgImageView.mas_left).offset(-8);
        make.size.mas_equalTo(CGSizeMake(30+jokeModel.upW+10, 30));
    }];
    
    _zanLableNum.text = [NSString stringWithFormat:@"%ld", (long)jokeModel.upTimes];
    [self.zanLableNum mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.top.equalTo(@0);
        make.size.mas_equalTo(CGSizeMake(jokeModel.upW+10, 30));
    }];

    
    [self.picImage sd_setImageWithURL:[NSURL URLWithString:jokeModel.imgsrc] placeholderImage:PLACEHOLDER_IMAGE];
    [self.picImage mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.digestLable);
        make.top.equalTo(self.digestLable.mas_bottom).offset(8);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH-20, jokeModel.picH));
    }];

}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
